﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WSManager.Wpf
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {




        public MainWindow()
        {
#if DEBUG
            //MyDebugListener.AddToListeners();
#endif
            InitializeComponent();
            Dispatcher.UnhandledException += Dispatcher_UnhandledException;
        }

        void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
   
            try
            {
                if (!e.Handled)
                {
                    MessageBox.Show(string.Format("{0}: {1}", e.Exception.GetType().Name, e.Exception.Message));
                }
            }
            catch
            {
                Close();
            }
        }

        private void mainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (viewModel.AutoSave) viewModel.SaveSelectedWeb();
            Properties.Settings.Default.Save();
        }
    }
}
